package chapter21

import java.awt.event.{ActionEvent, ActionListener}
import javax.swing.JButton

/**
 * Created by alex on 15-4-13.
 */
object Run {

//  implicit def stringWrapper(s: String) =
//    new RandomAccessSeq[char] {
//
//    }

  val button = new JButton

  //1
  button.addActionListener(new ActionListener {
    override def actionPerformed(e: ActionEvent): Unit = println("pressed!")
  })


  //2
  implicit def function2ActionListener(f: ActionEvent => Unit):ActionListener =  //传入一个函数
    //return type for ActionListener
    new ActionListener {
      override def actionPerformed(event: ActionEvent): Unit = f(event)
    }

  button.addActionListener(
    function2ActionListener(
      (_: ActionEvent) => println("pressed!")
    )
  )

  //3
  button.addActionListener(
    (_: ActionEvent) => println("pressed!")
  )

  implicit def int2String(x: Int) = x.toString
}